package com.irdstudio.efp.console.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.console.service.dao.TlrInfoDao;
import com.irdstudio.efp.console.service.domain.TlrInfo;
import com.irdstudio.efp.console.service.facade.TlrInfoService;
import com.irdstudio.efp.console.service.vo.TlrInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * Service Impl: 个贷系统操作员信息表服务实现
 *
 * @author gcb
 * @date 2020-01-03
 */
@Service("tlrInfoService")
public class TlrInfoServiceImpl implements TlrInfoService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(TlrInfoServiceImpl.class);

    @Autowired
    private TlrInfoDao tlrInfoDao;

    /**
     * 新增数据
     *
     * @param tlrInfoVo
     * @return
     */
    @Override
    public int insert(TlrInfoVO tlrInfoVo) {
        logger.debug("当前新增数据为:" + tlrInfoVo.toString());
        int num = 0;
        try {
            TlrInfo tlrInfo = new TlrInfo();
            beanCopy(tlrInfoVo, tlrInfo);
            num = tlrInfoDao.insert(tlrInfo);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param tlrInfoVo
     * @return
     */
    @Override
    public int deleteByPk(TlrInfoVO tlrInfoVo) {
        logger.debug("当前删除数据条件为:" + tlrInfoVo);
        int num = 0;
        try {
            TlrInfo tlrInfo = new TlrInfo();
            beanCopy(tlrInfoVo, tlrInfo);
            num = tlrInfoDao.deleteByPk(tlrInfo);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + tlrInfoVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param tlrInfoVo
     * @return
     */
    @Override
    public int updateByPk(TlrInfoVO tlrInfoVo) {
        logger.debug("当前修改数据为:" + tlrInfoVo.toString());
        int num = 0;
        try {
            TlrInfo tlrInfo = new TlrInfo();
            beanCopy(tlrInfoVo, tlrInfo);
            num = tlrInfoDao.updateByPk(tlrInfo);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + tlrInfoVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inTlrInfoVo
     * @return
     */
    @Override
    public TlrInfoVO queryByPk(TlrInfoVO inTlrInfoVo) {
        logger.debug("当前查询参数信息为:" + inTlrInfoVo);
        try {
            TlrInfo queryTlrInfo = new TlrInfo();
            beanCopy(inTlrInfoVo, queryTlrInfo);
            TlrInfo queryRslTlrInfo = tlrInfoDao.queryByPk(queryTlrInfo);
            if (Objects.nonNull(queryRslTlrInfo)) {
                return beanCopy(queryRslTlrInfo, new TlrInfoVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }
}
